/*
 * @描述信息:
 * @Author:   hunk
 */
const state = {
  selectedContract:{},
  userInfo: {
    userid: 0,
    avatar: '',
    unickname: '',
    sex: 0,
    telphone: '',
    cardid: '',
    usertype:0
  }, //用户信息
  ismanage: true,  //判断是否是管理员
  islogin: false,  //判断是否登陆
  isowner: false,
  // tabBarObj的配置项
  tabBarObj: {
    color: '#9B9B9B', //字体初始颜色
    selectedColor: '#FFAA58', //字体选中颜色
    // list: tenantTabBarlist
    // list: manageTabBarlist
  },
  baseUrl: 'http://111.231.92.29:9008/api/file/'
}

const mutations = {
  // 存储微信小程序的用户信息
  SET_USERINFO(state, value) {
    state.userInfo = value
  },
  SET_SELECTEDCONTRACTID(state, value) {
    console.log('SET_SELECTEDCONTRACTID', value)
    state.selectedContract = value
  },
  SET_TABBARLIST(state, value) {
    state.tabBarObj.list = value
  },
  SET_USERTYPE(state, value){
    state.userInfo.usertype = value
  }
}
const actions = {
  /*
   * 登录
   */
  handleLogin({ commit }, params) {
    return new Promise((resolve, reject) => {
      http
        .request(userApi.login, params, true)
        .then(response => {
          const { data } = response
          resolve(response)
        })
        .catch(error => {
          reject(error)
        })
    })
  },
  // 获取用户信息
  GetInfo({ commit },{userInfo}) {
    commit('SET_USERINFO', userInfo)
  },
}

export default {
  namespaced: true,
  state,
  mutations
}
